﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Truextend.Training.Model.Entities;
using Truextend.Training.Business.Dtos;

namespace Truextend.Training.Business.Tests
{
    [TestClass]
    public class UserCourseManagerTest : BaseTestClass
    {
        [Priority(4), TestMethod]
        public void AddUserCourse()
        {
            int beforeInset = 0;
            int afterInsert = 0;
            UserCourseManager userCourseManager = null;
            CourseInstanceManager courseInstanceManager = null;
            ExecuteManager(uow =>
            {
                userCourseManager = new UserCourseManager(uow);
                courseInstanceManager = new CourseInstanceManager(uow);
                UserCourse userCourse = new UserCourse
                {
                    CourseInstance = courseInstanceManager.GetAllCourseInstancesAvailable().ToList().First(),
                    FinalGrade = "0",
                    UserId = 1,
                    RegisterDate = DateTime.Now
                };

                beforeInset = userCourseManager.GetCount();
                userCourseManager.AddUserCourse(userCourse);
            }, () =>
            {
                afterInsert = userCourseManager.GetCount();
            }
                );
            Assert.AreEqual(beforeInset + 1, afterInsert);
        }

        [TestMethod]
        public void GetAllUserCoursesTest()
        {
            UserCourseManager userCourseManager = null;
            List<UserCourse> list = null;
            ExecuteManager(uow =>
            {
                userCourseManager = new UserCourseManager(uow);
                list = userCourseManager.GetAllUserCourses(1).ToList();
            });

            Assert.IsNotNull(list);
        }

        [TestMethod]
        public void GetInstanceUsersTest()
        {
            UserCourseManager userCourseManager = null;
            List<UserCourse> list = null;
            ExecuteManager(uow =>
            {
                userCourseManager = new UserCourseManager(uow);
                list = userCourseManager.GetInstanceUsers().ToList();
            });

            Console.Write(list.Count);
            Assert.IsNotNull(list);
        }
    }
}
